<?php
 /**
  *  @package ARXLib
  *  @version 2
  *  @subpackage Basic
  *  Parent of ARXLib Objects
  *
  *  @author Alexey Korepanov
  *  @copyright Ringo-Web Inc. 2004 - 2005
  */
class CARXControl
{
    var $m_visible;
    var $m_children;
    var $m_TagParams;
    var $FnValidate;

    var $m_printView;

    function CARXControl()
    {
        $this->m_visible = TRUE;
        $this->m_children = NULL;
        $this->m_TagParams = "";
        $this->FnValidate = "";
        $this->m_printView = FALSE;
    }

    function GetHTML()
    {
        $result = "";
        for ($i = 0; $i < count($this->m_children); $i++)
        {
            $result .= $this->m_children[$i]->GetHTML();
        }
        return $result;
    }
    
    function GetHTMLSaved()
    {
        return htmlspecialchars($this->GetHTML());
    }
    
    function GetVisible()
    {
        return $m_visible;
    }

    function SetVisible($visible)
    {
        $m_visible = $visible;
    }

    function SetFnValidate($FnValidate)
    {
        $this->FnValidate = $FnValidate;
    }

    function AddTagParam($param)
    {
        $this->m_TagParams .= " $param";
    }

    function SetPrintView($bPrintView = TRUE)
    {
        $this->m_printView = $bPrintView;
        for ($i = 0; $i < count($this->m_children); $i++)
        {
            $result .= $this->m_children[$i]->SetPrintView($bPrintView);
        }
    }

    function Validate()
    {
    	for ($i = 0; $i < count($this->m_children); $i++)
        {
            if (!($this->m_children[$i]->Validate()))
            {
            	return false;
            }
        }

        if ($this->FnValidate)
        {
        	if (!call_user_func($this->FnValidate, &$this))
            {
            	return false;
            }
        }
        return true;
    }

    function Submit()
    {
        for ($i = 0; $i < count($this->m_children); $i++)
        {
            $this->m_children[$i]->Submit();
        }
    }

    function InSubmitMode()
    {
        for ($i = 0; $i < count($this->m_children); $i++)
        {
            $inSubmit = $this->m_children[$i]->InSubmitMode();
            if ($inSubmit) return TRUE;
        }

        return FALSE;
    }

    function Insert(&$objArxControl)
    {
    	$this->m_children[] =& $objArxControl;
        $n = count($this->m_children);
    }

    function DebugDump()
    {
        echo "<p>" . serialize($this) . "</p>";
    }
}

?>
